package cn.kgm.template.server.controller;

import cn.kgm.core.http.request.BaseController;
import cn.kgm.core.jackson.JsonUtil;
import cn.kgm.template.server.entity.TemplateSelects;
import cn.kgm.template.server.service.TemplateSelectsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * # 技术改变自己 #
 * 模板数据,select标签表
 * @author kapp-i
 * @date   2024-03-18 15:36:57
 */
@Slf4j
@SpringBootTest
class TemplateSelectsTestService extends BaseController {

    @Autowired
    private TemplateSelectsService templateSelectsService;

    @Test
    void page() {
        IPage<TemplateSelects> page = getPage();
        LambdaQueryWrapper<TemplateSelects> wrapper = Wrappers.lambdaQuery(TemplateSelects.builder()
                .build());
        IPage<TemplateSelects> pages = templateSelectsService.page(page, wrapper);
        log.info("TemplateSelectsTestService::page===>{}", JsonUtil.toJson(pages.getRecords()));
    }

    @Test
    void get() {
        Long id = 1L;
        TemplateSelects templateSelects =templateSelectsService.getById(id);
        log.info("TemplateSelectsTestService::get===>{}", JsonUtil.toJson(templateSelects));
    }

    @Test
    void save() {
        TemplateSelects templateSelects = TemplateSelects.builder()
                .build();
            templateSelectsService.save(templateSelects);
        log.info("TemplateSelectsTestService::save===>{}", JsonUtil.toJson(templateSelects));
    }

    @Test
    void update() {
        TemplateSelects templateSelects = TemplateSelects.builder()
                .build();
            templateSelectsService.updateById(templateSelects);
        log.info("TemplateSelectsTestService::update===>{}", JsonUtil.toJson(templateSelects));
    }

    @Test
    void delete() {
        Long[] ids = new Long[]{0L};
            templateSelectsService.update(Wrappers.<TemplateSelects>lambdaUpdate()
                .set(TemplateSelects::getIsDel, true)
                .in(TemplateSelects::getId, ids));
        log.info("TemplateSelectsTestService::delete===>{}", JsonUtil.toJson(ids));
    }
}
